﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using System.Text;
public partial class bgDate_HourValue : System.Web.UI.Page
{
    string time;
    string sbID;
    string sbDesc;
    string xlDesc;
    string qsrq;
    string jsrq;
    DateTime time1;

    BLLData da = new BLLData();
    StringBuilder sb = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            time = Request.QueryString["time"];
            sbID = Request.QueryString["sbID"];
            sbDesc = HttpUtility.UrlDecode(Request.QueryString["sbDesc"]);
            xlDesc = HttpUtility.UrlDecode(Request.QueryString["xlDesc"]);

            this.hID.Value = sbID;
            this.hTime.Value = time;

            DateTime dt = DateTime.Now;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            if (DateTime.Parse(time) <= dt)
            {
                ArrayList list = da.RetListDLvalue(sbID, qsrq, jsrq);

                string[] value = (string[])list[0];
                string[] date = (string[])list[1];

                if (value.Length > 0)
                {
                    for (int i = 0; i < 24; i++)
                    {
                        time1 = DateTime.Parse(qsrq).AddHours(i);

                        sb.Append("<tr>");

                        sb.AppendFormat("<td align='center'>{0}</td>", sbDesc);

                        sb.AppendFormat("<td align='center'>{0}</td>", xlDesc);

                        sb.AppendFormat("<td align='center'>{0}</td>", time1.ToString());

                        for (int j = 0; j < date.Length; j++)
                        {
                            if (date[j] != null)
                            {
                                if (DateTime.Parse(date[j].ToString()) == time1)
                                {
                                    sb.AppendFormat("<td align='center'><input type=\"text\" id=\"txtValue" + i + "\" value='{0}' class=\"nvinput\" /></td>", value[j]);
                                    break;
                                }
                            }
                            else
                            {
                                sb.AppendFormat("<td align='center'><input type=\"text\" id=\"txtValue" + i + "\" value='{0}' class=\"nvinput\" /></td>", "");
                                break;
                            }
                        }
                    }
                }
                else
                    sb.Append("读取的日期内,无数据记录!");


                this.show.InnerHtml = sb.ToString();
            }
            else
            {
                Jscript.Alert("请选择正确日期！");
                this.Response.Write("<script language=javascript>window.close();</script>");
            }
        }
    }

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string[] val = new string[24];

        string id = this.hID.Value;
        string time = this.hTime.Value;

        val[0] = this.Hidden1.Value;
        val[1] = this.Hidden2.Value;
        val[2] = this.Hidden3.Value;
        val[3] = this.Hidden4.Value;
        val[4] = this.Hidden5.Value;
        val[5] = this.Hidden6.Value;
        val[6] = this.Hidden7.Value;
        val[7] = this.Hidden8.Value;
        val[8] = this.Hidden9.Value;
        val[9] = this.Hidden10.Value;
        val[10] = this.Hidden11.Value;
        val[11] = this.Hidden12.Value;
        val[12] = this.Hidden13.Value;
        val[13] = this.Hidden14.Value;
        val[14] = this.Hidden15.Value;
        val[15] = this.Hidden16.Value;
        val[16] = this.Hidden17.Value;
        val[17] = this.Hidden18.Value;
        val[18] = this.Hidden19.Value;
        val[19] = this.Hidden20.Value;
        val[20] = this.Hidden21.Value;
        val[21] = this.Hidden22.Value;
        val[22] = this.Hidden23.Value;
        val[23] = this.Hidden24.Value;

        bool flag = da.RetIsTrueByDL(id, time, val);

        if (flag == true)
            Jscript.AlertAndCloseWindow("保存成功!");
        else
            Jscript.Alert("保存失败!");

    }
}
